package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.Course1Dao;
import com.qfedu.stussm.dao.CourseDao;
import com.qfedu.stussm.entity.Course;
import com.qfedu.stussm.entity.Course1;
import com.qfedu.stussm.service.intf.Course1Service;
import com.qfedu.stussm.service.intf.CourseService;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Course1ServiceImpl implements Course1Service {
    @Autowired
    private Course1Dao dao;
    @Override
    public int add(Course1 course1) {
        return dao.add(course1);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit,String c1_name) {
        PageHelper.startPage(page, limit);
        if (c1_name != null && c1_name.length() >0){
            c1_name = "%"+c1_name+"%";
        } else {
            c1_name = null;
        }

        PageInfo<Course1> coursePageInfo = new PageInfo<>(dao.selectAll(c1_name));
        return new PageBeanVo(coursePageInfo.getTotal(), coursePageInfo.getList());
    }

    @Override
    public int update(Course1 course1) {
        return dao.update(course1);
    }

    @Override
    public int del(int c1_id) {
        return dao.del(c1_id);
    }
}
